/**
 * 
 */
package com.scpii.universal.download;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;

public class AppShareServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Logger log = Logger.getLogger(AppShareServlet.class);
	private String redirectUrl;

	public AppShareServlet() {
		super();
	}

	public void destroy() {
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = request.getParameter("id");
		if(id == null)
			return;
		int appId = Integer.parseInt(id);
		response.sendRedirect(redirectUrl+appId);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	}

	public void init() throws ServletException {
		String path = getServletContext().getInitParameter("config");
		Properties properties = new Properties();
		try {
			ResourceLoader resourceLoader = new DefaultResourceLoader();
			InputStream is = resourceLoader.getResource(path).getInputStream();
			properties.load(is);
			redirectUrl = properties.getProperty("APP_SHARE_DOWNLOAD_URL");
		} catch (Exception e) {
			e.printStackTrace();
			log.error("载入config.properties配置文件异常：", e);
		}
	}
}
